/* GUI CONVERTED from rqrqiq2.p (converter v1.76) Thu Aug  2 17:25:23 2001 */
/* rqrqiq2.p  - REQUISITION APPROVAL STATUS INQUIRY                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.11.1.5 $                                                         */
/*V8:ConvertMode=Report                                                       */

/* Revision: 8.5      LAST MODIFIED: 05/05/97   By: B. Gates         *J1Q2*   */
/* REVISION: 8.5      LAST MODIFIED: 10/24/97   BY: *J24N* Patrick Rowan      */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/05/98   BY: *K1PF* A. Shobha */
/* Revision: 8.5      LAST MODIFIED: 06/22/98   By: B. Gates          *J2QB*  */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Brian Compton      */
/* REVISION: 9.1      LAST MODIFIED: 10/21/99   BY: *J39R* Reetu Kapoor       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb                  */
/* $Revision: 1.11.1.5 $       BY: Tiziana Giustozzi   DATE: 07/12/01 ECO: *N104*      */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* Old ECO marker removed, but no ECO header exists *J314*              */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rqrqiq2_p_3 "Made"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_4 "Product Line Approvals Made"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_5 "Denials"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_8 "Horizontal Approvers/Reviewers"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_11 "Product Line Approvals Needed"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_13 "Needed"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_15 "Approval Status"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_16 "Approvals Completed"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_18 "Vertical Approvals Made"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_20 "Vertical Approvals Needed"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_22 "Valid Account!For Category"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_23 "Valid!Account"
/* MaxLen: Comment: */

&SCOPED-DEFINE rqrqiq2_p_24 "Required Apprs/Rvwrs Remaining"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

{rqconst.i}
{rqalttd.i new} /*APPROVER LIST TEMPTABLE DEFINITIONS*/

define variable approvals_completed as log no-undo
   label {&rqrqiq2_p_16}.
define variable required_aprs_rvwrs_remaining like rqf_horaprs_req
   no-undo label {&rqrqiq2_p_24}.
define variable denials as integer no-undo label {&rqrqiq2_p_5}.
define variable vert_approvals_made like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_18}.
define variable vert_approvals_needed like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_20}.
define variable horiz_approvals_made like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_3}.
define variable horiz_approvals_needed like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_13}.
define variable prod_line_approvals_made like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_4}.
define variable prod_line_approvals_needed like rqf_horaprs_req no-undo
   label {&rqrqiq2_p_11}.
define variable approval_count as integer no-undo.
define variable rqmnbr as character no-undo.
define variable put_rqmnbr as character no-undo.
define variable i as integer no-undo.
define variable acct_valid like mfc_logical no-undo
   column-label {&rqrqiq2_p_23}.

define variable category_valid like mfc_logical no-undo
   column-label {&rqrqiq2_p_22}.
define variable messages as character no-undo.
define variable msglevels as character no-undo.
define variable approved_action as character no-undo.
define variable denied_action as character no-undo.
define variable valid_acct like mfc_logical no-undo.

assign
   approved_action = getTermLabel("APPROVED",16)
   denied_action   = getTermLabel("DENIED",12).



/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
space(4)
   rqm_mstr.rqm_nbr
with frame a attr-space side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

FORM /*GUI*/ 
   approvals_completed         colon 35
   rqm_rtto_userid             colon 60
   rqm_rtdto_purch             colon 35
   rqm_aprv_stat               colon 60 label {&rqrqiq2_p_15}
   required_aprs_rvwrs_remaining   colon 35
   denials                     colon 60
   vert_approvals_needed       colon 35
   rqm_status                  colon 60
   vert_approvals_made         colon 35
with STREAM-IO /*GUI*/  frame b attr-space side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

find first gl_ctrl no-lock.

/*GET MOST RECENTLY ACCESSED REQ NUMBER AND DISPLAY*/

{gprun.i ""rqidf.p""
   "(input 'get', input 'reqnbr', input-output rqmnbr)"}

display rqmnbr @ rqm_mstr.rqm_nbr with frame a.

{gprun.i ""rqpma.p""}
find first rqf_ctrl no-lock.

{wbrp01.i}

mainloop:
repeat:
   if c-application-mode <> 'WEB' then
      prompt-for rqm_mstr.rqm_nbr with frame a
   editing:
      {mfnp.i rqm_mstr rqm_nbr rqm_nbr rqm_nbr rqm_nbr rqm_nbr}

      if recno <> ? then do:
         display rqm_nbr with frame a.
      end.
   end.
   {wbrp06.i &command = prompt-for
      &fields = "rqm_mstr.rqm_nbr"
      &frm = "a"}

   if c-application-mode <> 'WEB' or
      ( c-application-mode = 'WEB' and
      c-web-request begins 'DATA') then do:
      find rqm_mstr where rqm_nbr = input frame a rqm_nbr
         no-lock no-error.

      if not available rqm_mstr
      then do:
         {pxmsg.i &MSGNUM=193 &ERRORLEVEL=3} /*REQUISITION DOES NOT EXIST*/
         if c-application-mode = 'WEB' then return.
         undo, retry.
      end.

      /*SAVE ACCESSED REQ NUMBER FOR OTHER PGMS TO USE*/

      put_rqmnbr = rqm_nbr.

      {gprun.i ""rqidf.p""
         "(input 'put', input 'reqnbr', input-output put_rqmnbr)"}

      /*HIDE ALL FRAMES*/

      hide frame b no-pause.
      hide frame vert.
      hide frame job.
      hide frame horiz.
      hide frame horizcount.
      hide frame denials.
      hide frame alternates.
      hide frame cmt.
      hide frame prod_line.
      hide frame prod_line_count.
      hide frame invalid_account.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "terminal"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   displayblock:
   do:
      /*BUILD APPROVER LIST*/

      {gprun.i ""rqbal.p"" "(input recid(rqm_mstr))"}

      /*GET TEXT OF APPROVAL STATUS*/

      {gplngn2a.i
         &file=""rqm_mstr""
         &field=""rqm_aprv_stat""
         &code=rqm_aprv_stat
         &mnemonic=approval_stat_entry
         &label=approval_stat_desc}

      /*SEE IF FULLY APPROVED*/

      {gprun.i ""rqcfa.p""
         "(input rqm_nbr, output approvals_completed)"}

      run reqd-aprs (input rqm_nbr).

      run ct-denials (input rqm_nbr).

      if not rqm_direct then do:
         run appr-ct (input rqm_nbr, input rqm_job).

         vert_approvals_made = approval_count.

         vert_approvals_needed =
         max(0, rqf_vrtaprs_req - vert_approvals_made).
      end.

      display
         approvals_completed
         rqm_rtto_userid
         rqm_rtdto_purch
         approval_stat_desc @ rqm_aprv_stat
         required_aprs_rvwrs_remaining
         denials
         vert_approvals_made  when (not rqm_direct)
         vert_approvals_needed    when (not rqm_direct)
         rqm_status
      with frame b STREAM-IO /*GUI*/ .

      if rqm_direct then do:
         /*DISPLAY PRODUCT LINE APPROVERS*/

         for each ttdal no-lock
               break by ttdal_site by ttdal_prod_line by ttdal_apr_userid
            with frame prod_line:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame prod_line:handle).
            display
               ttdal_site     at 2
               ttdal_prod_line
               ttdal_apr_userid
               ttdal_is_approver
               ttdal_apr_required
               ttdal_is_reviewer
               ttdal_rvw_required
            with title color normal
               (getFrameTitle("PRODUCT_LINE_APPROVERS/REVIEWERS",42))
               width 80 STREAM-IO /*GUI*/ .

            find first rqda_det
               where rqda_nbr = rqm_nbr
               and rqda_apr_userid = ttdal_apr_userid
               no-lock no-error.

            if available rqda_det then do:
               display
                  approved_action
                  when (rqda_action = ACTION_APPROVE) @ rqda_action
                  format "x(16)"
                  denied_action
                  when (rqda_action = ACTION_DENY) @ rqda_action
                  format "x(16)"
                  rqda_date
                  string(rqda_time,'HH:MM:SS') @ rqda_time
                   WITH STREAM-IO /*GUI*/ .
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


         /*DISPLAY COUNTS OF PRODUCT LINE APPROVALS NEEDED*/

         if rqf_diraprs_req > 0 then do:
            for each rqd_det no-lock
                  where rqd_nbr = rqm_nbr
                  and rqd_status = LINE_STATUS_OPEN,
                  each pt_mstr no-lock
                  where pt_part = rqd_part
                  break by rqd_site by pt_prod_line
               with frame prod_line_count:
               /* SET EXTERNAL LABELS */
               setFrameLabels(frame prod_line_count:handle).
               if last-of(pt_prod_line) then do:
                  approval_count = 0.

                  for each ttdal no-lock
                        where ttdal_site = rqd_site
                        and ttdal_prod_line = pt_prod_line
                        and ttdal_is_approver:
                     find first rqda_det
                        where rqda_nbr = rqm_nbr
                        and rqda_apr_userid = ttdal_apr_userid
                        and rqda_action = ACTION_APPROVE
                        no-lock no-error.

                     if available rqda_det then do:
                        approval_count = approval_count + 1.
                     end.
                  end.

                  prod_line_approvals_made = approval_count.

                  prod_line_approvals_needed =
                  max(0, rqf_diraprs_req - prod_line_approvals_made).

                  display
                     rqd_site
                     pt_prod_line
                     prod_line_approvals_made
                     prod_line_approvals_needed
                  with title color normal
                     (getFrameTitle("PRODUCT_LINE_APPROVALS",29))
                     width 80 STREAM-IO /*GUI*/ .
               end.
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/

      end.
      else do:
         /*DISPLAY VERTICAL APPROVERS*/

         for each ttval no-lock with frame vert:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame vert:handle).
            display
               ttval_apr_userid at 8
               ttval_is_approver
               ttval_apr_required
               ttval_is_reviewer
               ttval_rvw_required
            with title color normal
               (getFrameTitle("VERTICAL_APPROVERS/REVIEWERS",37))
               width 80 STREAM-IO /*GUI*/ .

            find first rqda_det
               where rqda_nbr = rqm_nbr
               and rqda_apr_userid = ttval_apr_userid
               no-lock no-error.

            if available rqda_det then do:
               display
                  approved_action
                  when (rqda_action = ACTION_APPROVE) @ rqda_action
                  format "x(16)"
                  denied_action
                  when (rqda_action = ACTION_DENY) @ rqda_action
                  format "x(16)"
                  rqda_date
                  string(rqda_time,'HH:MM:SS') @ rqda_time
                   WITH STREAM-IO /*GUI*/ .
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


         /*DISPLAY JOB APPROVERS*/

         for each ttjal no-lock with frame job:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame job:handle).
            display
               ttjal_apr_userid at 8
               ttjal_is_approver
               ttjal_apr_required
               ttjal_is_reviewer
               ttjal_rvw_required
            with title color normal
               (getFrameTitle("JOB_APPROVERS/REVIEWERS",30))
               width 80 STREAM-IO /*GUI*/ .

            find first rqda_det
               where rqda_nbr = rqm_nbr
               and rqda_apr_userid = ttjal_apr_userid
               no-lock no-error.

            if available rqda_det then do:
               display
                  approved_action
                  when (rqda_action = ACTION_APPROVE) @ rqda_action
                  format "x(16)"
                  denied_action
                  when (rqda_action = ACTION_DENY) @ rqda_action
                  format "x(16)"
                  rqda_date
                  string(rqda_time,'HH:MM:SS') @ rqda_time
                   WITH STREAM-IO /*GUI*/ .
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


         /*DISPLAY HORIZONTAL APPROVERS*/

         for each tthal no-lock
               break by tthal_category by tthal_apr_userid
            with frame horiz:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame horiz:handle).
            display
               tthal_category at 4
               tthal_apr_userid
               tthal_is_approver
               tthal_apr_required
               tthal_is_reviewer
               tthal_rvw_required
            with title color normal
               (getFrameTitle("HORIZONTAL_APPROVERS/REVIEWERS",39))
               width 80 STREAM-IO /*GUI*/ .

            find first rqda_det
               where rqda_nbr = rqm_nbr
               and rqda_apr_userid = tthal_apr_userid
               no-lock no-error.

            if available rqda_det then do:
               display
                  approved_action
                  when (rqda_action = ACTION_APPROVE) @ rqda_action
                  format "x(16)"
                  denied_action
                  when (rqda_action = ACTION_DENY) @ rqda_action
                  format "x(16)"
                  rqda_date
                  string(rqda_time,'HH:MM:SS') @ rqda_time
                   WITH STREAM-IO /*GUI*/ .
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


         /*DISPLAY COUNTS OF HORIZONTAL APPROVALS NEEDED*/

         if rqf_horaprs_req > 0 then do:
            for each rqd_det no-lock
                  where rqd_nbr = rqm_nbr
                  and rqd_status = LINE_STATUS_OPEN
                  and rqd_category > ""
                  break by rqd_category
               with frame horizcount:
               /* SET EXTERNAL LABELS */
               setFrameLabels(frame horizcount:handle).
               if last-of(rqd_category) then do:
                  approval_count = 0.

                  for each tthal no-lock
                        where tthal_category = rqd_category
                        and tthal_is_approver:
                     find first rqda_det
                        where rqda_nbr = rqm_nbr
                        and rqda_apr_userid = tthal_apr_userid
                        and rqda_action = ACTION_APPROVE
                        no-lock no-error.

                     if available rqda_det then do:
                        approval_count = approval_count + 1.
                     end.
                  end.

                  horiz_approvals_made = approval_count.

                  horiz_approvals_needed =
                  max(0, rqf_horaprs_req - horiz_approvals_made).

                  display
                     rqd_category at 30
                     horiz_approvals_made
                     horiz_approvals_needed
                  with title color normal
                     (getFrameTitle("HORIZONTAL_APPROVALS",26))
                     width 80 STREAM-IO /*GUI*/ .
               end.
            end.
         end.

         
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/

      end.

      /*DISPLAY ANY INVALID ACCOUNTS*/

      for each rqd_det no-lock
            where rqd_nbr = rqm_nbr with frame invalid_account:
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame invalid_account:handle).
         acct_valid = true.

         category_valid = true.

         /*GPGLVERO.P RETURNS A LIST OF MESSAGE NUMBERS.
         IF ANY ERROR-LEVEL THEN THE REQ WILL NOT ACHIEVE
         FINAL APPROVAL.*/

         {gprunp.i "gpglvpl" "p" "initialize"}
         {gprunp.i "gpglvpl" "p" "set_disp_msgs" "(input false)"}
         {gprunp.i "gpglvpl" "p" "validate_fullcode"
            "(input rqd_acct,
              input rqm_sub,
              input rqm_cc,
              input rqd_project,
              output valid_acct)"}
         {gprunp.i "gpglvpl" "p" "get_msgs"
            "(output messages, output msglevels)"}

         if lookup("3",msglevels) > 0 then do:
            acct_valid = false.
         end.

         /*CHECK CATEGORIES*/

         if rqd_category > "" then do:
            find last rqcd_det
               where rqcd_category = rqd_category
               and rqcd_acct_from <= rqd_acct
               and rqcd_acct_to >= rqd_acct
               and rqcd_sub_from <= rqm_sub
               and rqcd_sub_to >= rqm_sub
               no-lock no-error.

            if not available rqcd_det then do:
               category_valid = false.
            end.

         end.

         if not acct_valid or not category_valid
         then do:
            display
               rqd_line   at 8
               rqd_acct
               rqm_sub
               rqm_cc
               rqd_project
               rqd_category
               acct_valid
               category_valid
            with title color normal
               (getFrameTitle("INVALID_ACCOUNTS",21))
               width 80 STREAM-IO /*GUI*/ .

         end.

      end.

      /*DISPLAY ANY DENIALS*/

      for each rqda_det no-lock
            where rqda_nbr = rqm_nbr
            and rqda_action = ACTION_DENY
         with frame denials:

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame denials:handle).
         display
            rqda_apr_userid at 27
            rqda_date
            string(rqda_time,'HH:MM:SS') @ rqda_time
         with title color normal (getFrameTitle("DENIALS",14))
            width 80 STREAM-IO /*GUI*/ .
      end.

      
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


      /*DISPLAY ALTERNATES*/

      for each ttalt no-lock
         with frame alternates:
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame alternates:handle).
         display
            ttalt_apr_userid at 3
            ttalt_alt_userid
            ttalt_is_admin_apr
            ttalt_is_alt_apr
            ttalt_is_horizontal
            ttalt_is_vertical
            ttalt_is_job
            ttalt_is_direct
         with title color normal (getFrameTitle("ALTERNATES",13))
            width 80 STREAM-IO /*GUI*/ .
      end.

      
/*GUI*/ {mfguichk.i  &label=displayblock} /*Replace mfrpchk*/


      /*DISPLAY APPROVAL COMMENTS*/

      clear frame cmt all no-pause.

      FORM /*GUI*/ 
         cmt_cmmt[1] no-label
      with STREAM-IO /*GUI*/  frame cmt down title color normal
         (getFrameTitle("COMMENTS",13)) width 80.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame cmt:handle).

      for each cmt_det no-lock
         where cmt_indx = rqm_apr_cmtindx:
         do i = 1 to 15:
            if cmt_cmmt[i] > "" then do:
               display cmt_cmmt[i] @ cmt_cmmt[1] with frame cmt STREAM-IO /*GUI*/ .
               down 1 with frame cmt.
            end.

         end.

      end.

   end.

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

   {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}
end.

PROCEDURE reqd-aprs:
   define input parameter c-rqm_nbr like rqm_mstr.rqm_nbr.
   /*COUNT REQUIRED APPROVERS/REVIEWERS REMAINING*/

   required_aprs_rvwrs_remaining = 0.

   for each ttcal no-lock
      where ttcal_required:
      find first rqda_det
         where rqda_nbr = c-rqm_nbr
         and rqda_apr_userid = ttcal_apr_userid
         and rqda_action = ACTION_APPROVE
         no-lock no-error.

      if not available rqda_det then do:
         required_aprs_rvwrs_remaining =
         required_aprs_rvwrs_remaining + 1.
      end.

   end.

END PROCEDURE.

PROCEDURE ct-denials:
   define input parameter c-rqm_nbr like rqm_mstr.rqm_nbr.
   /*COUNT DENIALS*/

   denials = 0.

   for each rqda_det no-lock
      where rqda_nbr = c-rqm_nbr
        and rqda_action = ACTION_DENY:
      denials = denials + 1.
   end.

END PROCEDURE.

PROCEDURE appr-ct:
   define input parameter c-rqm_nbr like rqm_mstr.rqm_nbr.
   define input parameter c-rqm_job like rqm_mstr.rqm_job.
   /*COUNT VERTICAL APPROVALS*/

   approval_count = 0.

   if c-rqm_job > "" then do:
      for each ttjal where ttjal_is_approver no-lock:
         /*NOTE WE JUST COUNT THE NUMBER OF JOB APPROVERS
         AS THE COUNT IS USED FOR THE NEXT STEP*/

         find first rqda_det
            where rqda_nbr = c-rqm_nbr
              and rqda_apr_userid = ttjal_apr_userid
              and rqda_action = ACTION_APPROVE
         no-lock no-error.

         if available rqda_det
         then do:
            approval_count = approval_count + 1.
         end.

      end.

   end.

   for each ttval where ttval_is_approver no-lock:
      find first rqda_det
         where rqda_nbr = c-rqm_nbr
           and rqda_apr_userid = ttval_apr_userid
           and rqda_action = ACTION_APPROVE
      no-lock no-error.

      if available rqda_det
      then do:
         approval_count = approval_count + 1.
      end.

   end.

END PROCEDURE.

{wbrp04.i &frame-spec = a}
